package com.demo.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * 可以使用--spring.profiles.active 来控制profile的生效，可以指定多个 --spring.profiles.active=test
 */
@SpringBootApplication
public class App {
    public static void main(String[] args) {

        // ConfigurableApplicationContext context = SpringApplication.run(App.class,args);

        SpringApplication app = new SpringApplication(App.class);
        // 代码的方式指定生效的profile
        app.setAdditionalProfiles("test");

        ConfigurableApplicationContext context = app.run(args);

        System.out.println("jdbc.username: " + context.getEnvironment().getProperty("jdbc.username"));
        System.out.println("jdbc.password: " + context.getEnvironment().getProperty("jdbc.password"));
        System.out.println("springboot.myname: " + context.getEnvironment().getProperty("springboot.myname"));
        System.out.println("jdbc.url: " + context.getEnvironment().getProperty("jdbc.url"));
        System.out.println("hosts: " + context.getBean(TomcatProperties.class));

        context.close();
    }
}
